package offer;

import java.util.Stack;

class offer30 {
    public static void main(String[] args) {
        Stack<Integer> stack = new Stack();
        stack.push(1);
        stack.push(2);
        int min=2000000000;
        for(Integer i :stack)
        {
            if(i<min)
            {
                min=i;
            }

        }
    }

}
class MinStack {
    Stack<Integer> first;
    Stack<Integer> second;
    /** initialize your data structure here. */
    public MinStack() {
        first= new Stack<>();
        second = new Stack<>();
    }

    public void push(int x) {
       first.push(x);
       if(second.isEmpty())
       {
           second.push(x);
       }else
       {
           if(second.peek()>x)
           {
               second.push(x);
           }
       }
    }

    public void pop() {
        Integer pop = first.pop();

        if(pop==second.peek())
        {
            second.pop();
        }
        if(!first.isEmpty()&&second.isEmpty())
        {
            second.push(pop);
        }

    }

    public int top() {
        Integer peek = first.peek();
        return peek;
    }

    public int min() {

            return second.peek();


    }
}
